<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>发射机列表</title>
    <link rel="stylesheet" th:href="@{../../component/pear/css/pear.css}"/>
</head>

<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-13 search-collapse">
            <form class="layui-form" id="formId">
                <div class="layui-form-item">
                    <label class="layui-form-label">发射机ID：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-required name="transCode" placeholder="请输入发射机ID" type="text"/>
                    </div>

                    <label class="layui-form-label" style="width: 7%">发射机名称：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-required name="transName" placeholder="请输入发射机名称" type="text"/>
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-filter="myTable-query" lay-submit>
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button class="pear-btn pear-btn-md" type="reset">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="myTable" lay-filter="myTable" ></table>
    </div>
    <div class="layui-card-body">
        <table id="warnTable" lay-filter="warnTable"></table>
    </div>
</div>

<script th:src="@{../../component/layui/layui.js}"></script>
<script th:src="@{../../component/pear/pear.js}"></script>
<script type="text/html" id="power-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="setting">指令下发</a>
    <a class="layui-btn layui-btn-xs" lay-event="runningstatus">运行状态</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/html" id="table-status">
    {{#if (d.status == '0') { }}
    <span class="pear-text">在线</span>
    {{# }else if(d.status == '1'){ }}
    <span style="color: #1e9fff">离线</span>
    {{# } }}
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'popup'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;
        let MODULE_PATH = "/system/transmitter/";

        setInterval(function () {
            table.reloadData('myTable');
        }, 5000);

        form.on('submit(myTable-query)', function (data) {
            table.reload('myTable', {where: data.field})
            return false;
        });

        let cols = [
            [
                {
                    title: '台站ID',
                    field: 'stationCode',
                    align: 'center'
                },
                {
                    title: '发射机ID',
                    field: 'transCode',
                    align: 'center'
                },
                {
                    title: '发射机名称',
                    field: 'transName',
                    align: 'center'
                },
                {
                    title: '最大功率',
                    field: 'power',
                    align: 'center'
                },
                {
                    title: '地址',
                    field: 'address',
                    align: 'center'
                },
                {
                    title: '经度',
                    field: 'longitude',
                    align: 'center'
                },
                {
                    title: '纬度',
                    field: 'latitude',
                    align: 'center'
                },
                // {
                //     title: '更新时间',
                //     field: 'sendTime',
                //     align: 'center',
                //     templet: "<div>{{layui.util.toDateString(d.sendTime)}}</div>"
                // },
                // {
                //     title: '创建时间',
                //     field: 'createTime',
                //     align: 'center',
                //     templet: "<div>{{layui.util.toDateString(d.createTime)}}</div>"
                // },
                {
                    title: '状态',
                    field: 'status',
                    templet: '#table-status',
                    align: 'center'
                },
                {
                    title: '操作',
                    toolbar: '#barDemo',
                    width: '20%'
                }
            ]
        ]
        let warncols = [
            [
                {
                    title: '故障ID',
                    field: 'alarmId',
                    align: 'center'
                },
                {
                    title: '台站ID',
                    field: 'stationCode',
                    align: 'center'
                },
                {
                    title: '发射机ID',
                    field: 'transCode',
                    align: 'center'
                },
                {
                    title: '故障开始时间',
                    field: 'start_time',
                    align: 'center',
                    templet: "<div>{{layui.util.toDateString(d.start_time)}}</div>"
                },
                {
                    title: '故障结束时间',
                    field: 'endTime',
                    align: 'center',
                    templet: "<div>{{layui.util.toDateString(d.endTime)}}</div>"
                },
                {
                    title: '故障类型',
                    field: 'exceptionCode',
                    align: 'center',
                },
                {
                    title: '故障级别',
                    field: 'exceptionLevel',
                    align: 'center',
                },
                {
                    title: '状态数据值',
                    field: 'exceptionData',
                    align: 'center',
                },
                {
                    title: '故障上报时间',
                    field: 'sendTime',
                    align: 'center',
                    templet: "<div>{{layui.util.toDateString(d.sendTime)}}</div>"
                }
            ]
        ]
        table.render({
            elem: '#myTable',
            url: MODULE_PATH +'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#power-toolbar',
            defaultToolbar: [],
            cellMinWidth: 'auto',
            done: function (res, curr, count) {
            }
        });

        table.on('toolbar(myTable)', function(obj){
            if(obj.event === 'add'){
                layer.open({
                    type: 2,
                    title: "添加发射机",
                    area: ['100%', '100%'],
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    skin: 'layui-layer-rim',
                    content: ['/system/view/transmitter_add', "no"],
                    success: function (layero, index) {
                    }
                });
            }
        });

        table.on('tool(myTable)', function(obj) {
            var rowIndex = $(obj.tr).attr("data-index");
            var data = obj.data;
            json = JSON.stringify(data);
            switch(obj.event) {
                case 'setting':
                    layer.open({
                        type: 2,
                        title: "发射机指令下发",
                        area: ['100%', '100%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-rim',
                        content: ["/system/view/setting?stationCode="+data.stationCode+"&&transCode="+data.transCode, "no"],
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find("[name='stationCode']").val(data.stationCode);
                            body.find("[name='transCode']").val(data.transCode);
                        }
                    });
                    break;
                case 'edit':
                    layer.open({
                        type: 2,
                        title: "发射机编辑页面",
                        area: ['100%', '100%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-rim',
                        content: ["/system/view/getTransmitterEdit", "no"],
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find("[name='stationCode']").val(data.stationCode);
                            body.find("[name='transCode']").val(data.transCode);
                            body.find("[name='transName']").val(data.transName);
                            body.find("[name='status']").val(data.status);
                            body.find("[name='transIp1']").val(data.transIp1);
                            body.find("[name='transHttpsPort']").val(data.transHttpsPort);
                            body.find("[name='transHttpPort']").val(data.transHttpPort);
                            body.find("[name='power']").val(data.power);
                            body.find("[name='antenna']").val(data.antenna);
                            body.find("[name='antennaProgram']").val(data.antennaProgram);
                            body.find("[name='isHopped']").val(data.isHopped);
                            body.find("[name='address']").val(data.address);
                            body.find("[name='longitude']").val(data.longitude);
                            body.find("[name='latitude']").val(data.latitude);
                            body.find("[name='createTime']").val(data.createTime);
                            body.find("[name='stationIP']").val(data.stationIP);
                            body.find("[name='stationPort']").val(data.stationPort);
                            body.find("[name='statusPeriod']").val(data.statusPeriod);
                            body.find("[name='oneTaskPlayTime']").val(data.oneTaskPlayTime);
                            body.find("[name='sendTime']").val(data.sendTime);
                            body.find("[name='operType']").val(data.operType);
                            body.find("[name='transReset']").val(data.transReset);
                        }
                    });
                    break;
                case 'delete':
                    layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" }, function (index) {
                        $.ajax({
                            url: MODULE_PATH +"delTransmitter",
                            type: 'POST',
                            contentType: 'application/json;charset=UTF-8',
                            data: json,
                            success: function (data) {
                                if (data.code === 200) {
                                    popup.success(data.msg);
                                    table.reloadData('myTable');
                                } else {
                                    popup.failure(data.msg);
                                    table.reloadData('myTable');
                                }
                            },
                            error: function () {
                                popup.failure("删除失败!")
                            }
                        });
                    });
                    break;
                case 'runningstatus':
                    layer.open({
                        type: 2,
                        title: "发射机运行状态页面",
                        area: ['100%', '100%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-rim',
                        content: ["/system/view/getTransmitterRunningStatus?stationCode="+data.stationCode+"&&transCode="+data.transCode, "no"],
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find("[name='stationCode']").val(data.stationCode);
                            body.find("[name='transCode']").val(data.transCode);
                            // body.find("[name='viewTime']").val(data.viewTime);
                            // body.find("[name='outputPower']").val(data.outputPower);
                            // body.find("[name='reflectedPower']").val(data.reflectedPower);
                            // body.find("[name='lopsidedPower']").val(data.lopsidedPower);
                            // body.find("[name='powerAmplifierVoltage']").val(data.powerAmplifierVoltage);
                            // body.find("[name='powerAmplifierCurrent']").val(data.powerAmplifierCurrent);
                            // body.find("[name='temperature']").val(data.temperature);
                            // body.find("[name='powerTemperature']").val(data.powerTemperature);
                            // body.find("[name='modulateDegree']").val(data.modulateDegree);
                            // body.find("[name='channelAFreq']").val(data.channelAFreq);
                            // body.find("[name='channelARfChState']").val(data.channelARfChState);
                            // body.find("[name='channelATimeSlot']").val(data.channelATimeSlot);
                            // body.find("[name='channelAEqualization']").val(data.channelAEqualization);
                            // body.find("[name='channelARfChMod']").val(data.channelARfChMod);
                            // body.find("[name='channelARfChBand']").val(data.channelARfChBand);
                            // body.find("[name='channelARfChASource']").val(data.channelARfChASource);
                            // body.find("[name='channelBFreq']").val(data.channelBFreq);
                            // body.find("[name='channelBRfChState']").val(data.channelBRfChState);
                            // body.find("[name='channelBTimeSlot']").val(data.channelBTimeSlot);
                            // body.find("[name='channelBEqualization']").val(data.channelBEqualization);
                            // body.find("[name='channelBRfChMod']").val(data.channelBRfChMod);
                            // body.find("[name='channelBRfChBand']").val(data.channelBRfChBand);
                            // body.find("[name='channelBRfChASource']").val(data.channelBRfChASource);
                            // body.find("[name='channelBRfChAUrl']").val(data.channelBRfChAUrl);
                            // body.find("[name='channelCFreq']").val(data.channelCFreq);
                            // body.find("[name='channelCRfChState']").val(data.channelCRfChState);
                            // body.find("[name='channelCTimeSlot']").val(data.channelCTimeSlot);
                            // body.find("[name='channelCEqualization']").val(data.channelCEqualization);
                            // body.find("[name='channelCRfChMod']").val(data.channelCRfChMod);
                            // body.find("[name='channelCRfChBand']").val(data.channelCRfChBand);
                            // body.find("[name='channelCRfChASource']").val(data.channelCRfChASource);
                            // body.find("[name='channelCRfChAUrl']").val(data.channelCRfChAUrl);
                            // body.find("[name='channelDFreq']").val(data.channelDFreq);
                            // body.find("[name='channelDRfChState']").val(data.channelDRfChState);
                            // body.find("[name='channelDTimeSlot']").val(data.channelDTimeSlot);
                            // body.find("[name='channelDEqualization']").val(data.channelDEqualization);
                            // body.find("[name='channelDRfChMod']").val(data.channelDRfChMod);
                            // body.find("[name='channelDRfChBand']").val(data.channelDRfChBand);
                            // body.find("[name='channelDRfChASource']").val(data.channelDRfChASource);
                            // body.find("[name='channelDRfChAUrl']").val(data.channelDRfChAUrl);
                            // body.find("[name='sendTime']").val(data.sendTime);
                        }
                    });
                    break;
            }
        });
    })
</script>
</body>

</html>
